

jQuery(function ($) {
    //畜牧资讯
    var params = {
        "ArticleCat": {
            "url": "hyhq",
            "@column": "id"
        },
        "ArticleCat[]": {
            "count": 7,
            "ArticleCat": {
                "parent_id@": "ArticleCat/id",
                "@column": "id"
            }
        }
    };
    send_ajax('post', '/get', params, function callback(res) {
        var cat_ids = [];
        if (res.code == 200 && res["ArticleCat[]"]) {
            var data = res["ArticleCat[]"];
            for(var n = 0;n<data.length;n++){
                var a_data = data[n];
                cat_ids.push(a_data.id);
            }
            var hyhqParam={
                "Article[]": {
                    "count": "7",
                    "Article": {
                        "@column": "id,title,img",
                        "cat_id{}":cat_ids,
                        "@order": "rank-,update_time-"
                    }
                }
            }
            send_ajax('post', '/get', hyhqParam, function callback(res) {
                if(res["Article[]"].length){
                    var data =  res["Article[]"];
                    var firstImg = data[0];
                    $('.hyhq').append('<a href="/article-'+firstImg.id+'.html" target="_blank"><img src="'+firstImg.img+'" alt="'+firstImg.title+'"></a>')
                    var html = '';
                    for (var i = 1; i < data.length; i++) {
                        var a_data = data[i];
                        html += "<li><i></i><a  target=\"_blank\" href=\"/article-" +a_data.id + ".html\">" + a_data.title + "</a></li>";
                    };
                    $('#hyhq').html(html);
                }
            });

            
        }
    });
    //畜牧问答
    var params = {
            "ArticleCat": {
                "url": "xmjs"
            },
            "Article[]": {
                "count": 7,
                "Article": {
                    "@order": "rank-",
                    "cat_id@": "ArticleCat/id"
                }
            } 
    };
    send_ajax('post', '/get', params, function callback(res) {
        if (res.code == 200 && res["Article[]"]) {
            var firstImg = res["Article[]"][0];
            $('.xmjs').append('<a href="/article-'+firstImg.id+'.html" target="_blank"><img src="'+firstImg.img+'" alt="'+firstImg.title+'"></a>')
            var data = res["Article[]"];
            var html = '';
            for (var i = 1; i < data.length; i++) {
                var a_data = data[i];
                html += "<li><i></i><a  target=\"_blank\" href=\"/article-" + a_data.id + ".html\">" +a_data.title + "</a></li>";
            };
            $('#xmjs').html(html);
        }
    });
    //咨询问答 右侧广告位
    var params = {
        positionSn:'article_right',
        pageSn:'request_index',
        count:1
    };
    send_ajax('get', '/api/ad/list', params, function callback(res) {
        if (res.code == 200 && res.data.length) {
            var data =res.data[0];
            $('.yc_content_pic').html('<a href="' + data.href + '" target="_blank"><img src="' + isImgHttp(data.img) + '" alt="' + data.img_alt + '"></a>');
        }
    });

    //咨询问答 上部广告位
    var params = {
        "WebPage": {
            "page_sn": "topic_list"
        },
        "AdPosition": {
            "position_sn": "bottom_full"
        },
        "Ad": {
            "page_id@": "WebPage/id",
            "position_id@": "AdPosition/id"
        }
    };
    send_ajax('post', '/get', params, function callback(res) {
        if (res.code && res.Ad) {
            var data = res.Ad;
            $('.artist_pic_show').html('<a href="' + data.ad_link + '" target="_blank"><img src="' + isImgHttp(data.img) + '" title="" alt="' + data.img_alt + '"></a>');
        }
    });
});